package string;

import java.util.Scanner;

public class StringDemo3 {
    public static void main(String[] args) {
        // 定义两个个变量记录正确的用户名和密码
        String rightusername = "admin";
        String rightpassword = "123456";

        // 键盘输入用户名和密码

        for (int i = 0; i < 3; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名：");
            String username = sc.next();
            System.out.println("请输入密码：");
            String password = sc.next();

            // 判断用户名和密码是否正确
            if (username.equals(rightusername) && password.equals(rightpassword)) {
                System.out.println("登录成功");
                break;
            } else {
                if (i == 2) {
                    System.out.println("账户被锁定");
                }else {
                    System.out.println("用户名或密码错误，请重新输入,您还有 " + (2 - i) + " 次机会");
                }
            }
        }
    }
}
